//
//  BQYLDetailsViewController.m
//  BeeQuick
//
//  Created by 杨雷 on 2016/11/21.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQYLDetailsViewController.h"
#import <UIImageView+WebCache.h>
#import "BQYLDetailsTableViewCell.h"
#import "BQYLHeadView.h"
#import "BQHomeGoodModel.h"

@interface BQYLDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation BQYLDetailsViewController
{
    BQHomeGoodModel *_goodModel;
}

- (instancetype)initWithGoodModel:(BQHomeGoodModel *)goodModel andIndexPath:(NSIndexPath *)currentIndexPath
{

    self = [super initWithNibName:nil bundle:nil];
    
    if (self) {
    
        _goodModel = goodModel;
        _currentIndexPath = currentIndexPath;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}


#pragma mark - 界面
- (void)setupUI
{

    //MARK: 上面的图片 和 内容 (作为tableView的头)
    UIView *topView = [[UIView alloc]init];
    topView.backgroundColor = [UIColor whiteColor];
    
    topView.bounds = CGRectMake(0, 0, kScreenW, kScreenW + 73);
    
    
    
    
    //图片
    UIImageView *topImageView = [[UIImageView alloc]init];
    
    NSMutableString *urlStr = [NSMutableString stringWithFormat:@"%@", _goodModel.img];
    
    NSRange range = [urlStr rangeOfString:@"@200w_200h_90Q.jpg"];
    
    [urlStr deleteCharactersInRange:range];
    
    [topImageView sd_setImageWithURL:[NSURL URLWithString:urlStr.copy]];
    
    [topView addSubview:topImageView];
    
    
    //下面的图片
    UIImageView *footImageView = [[UIImageView alloc]init];
    
    [footImageView sd_setImageWithURL:[NSURL URLWithString:urlStr.copy]];
    
    
    
    
    
    
    
    //内容View
    BQYLHeadView *nameView = [BQYLHeadView headView];
    
    nameView.model = _goodModel;
    [topView addSubview:nameView];
    
    //MARK:tableView
    UITableView *detailsTableView = [[UITableView alloc]init];
    [self.view addSubview:detailsTableView];

    detailsTableView.tableHeaderView = topView;
    
    detailsTableView.tableFooterView = footImageView;
    
    footImageView.frame = CGRectMake(0, 0, kScreenW, kScreenW);
    
    detailsTableView.showsVerticalScrollIndicator = NO;
    
    
    //下面的商品View
    

    
    //注册
    
    
    [detailsTableView registerNib:[UINib nibWithNibName:@"BQYLDetailsTableViewCell" bundle:nil] forCellReuseIdentifier:@"cellID"];
    
    
    //代理
    detailsTableView.delegate = self;
    detailsTableView.dataSource = self;

    
    //MARK:布局
    [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(topView);
        make.size.mas_equalTo(CGSizeMake(kScreenW, kScreenW));
    }];
    
    [nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topView);
        make.top.equalTo(topImageView.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(kScreenW, 73));
    }];
    
    
    [detailsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    
    
}

- (void)jumpMarket
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

//    return self.detailsModel.had_pm ? 5:4;
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BQYLDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
//    cell.model = _goodsModel;
    
    
    switch (indexPath.row)
    {
        case 0:
            cell.miaoShuLabel.text = @"品       牌";
            cell.neiRongLabel.text = _goodModel.brand_name;
            break;
        case 1:
            cell.miaoShuLabel.text = @"产品规格";
            cell.neiRongLabel.text = _goodModel.specifics;
            break;
        case 2:
            cell.miaoShuLabel.text = @"图文详情";
            cell.neiRongLabel.text = nil;
            break;
            
        default:
            break;
    }
    
    
    return cell;
}



@end
